#import "file_config_library.h"

/*main
*/
UIAnimationObject g_CfgLibraryMainAnimationBackground;
UIImageObject g_CfgLibraryMainImageBox;
UIMenuItemImageObject g_CfgLibraryMainItemExperiment;
UIMenuItemImageObject g_CfgLibraryMainItemTreasure;
UIMenuItemImageObject g_CfgLibraryMainItemCredits;
UIMenuItemImageObject g_CfgLibraryMainItemBack;

/*experiment
*/
UIImageObject g_CfgLibraryExperimentImageBackgournd;
UIImageObject g_CfgLibraryExperimentImageContainerRune;
UIImageObject g_CfgLibraryExperimentImageContainerHeart;
UIMenuItemImageObject g_CfgLibraryExperimentItemShake;
char g_CfgLibraryExperimentImageBoxPath[STRING_BUF_SIZE];
CGPoint g_CfgLibraryExperimentImageBoxBasePosition;
CGSize g_CfgLibraryExperimentImageBoxSize;

/*treasure
*/
char g_CfgLibraryTreasureImageLabelWeaopnPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageLabelItemPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageLabelExhibitionPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageTableSelectPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageTableUnselectPath[STRING_BUF_SIZE];
CGPoint g_CfgLibraryTreasureItemTableWeaponPosition;
CGPoint g_CfgLibraryTreasureItemTableItemPosition;
CGPoint g_CfgLibraryTreasureItemTableExhibitionPosition;
char g_CfgLibraryTreasureImageCoverPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageHolderPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageDetailBackPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageSelectedPath[STRING_BUF_SIZE];
char g_CfgLibraryTreasureImageDescirptionBackPath[STRING_BUF_SIZE];
CGPoint g_CfgLibraryTreasureCoverPosition;
CGPoint g_CfgLibraryTreasureHolderBasePosition;
CGPoint g_CfgLibraryTreasureDetailPosition;
CGPoint g_CfgLibraryTreasureDescriptionPosition;
CGPoint g_CfgLibraryTreasureDescriptionTextBasePostion;
UIMenuItemImageObject g_CfgLibraryTreasureItemBack;

void CfgLibraryLoadConfigFile(void)
{
	char _Buffer[256];
	FILE *_ConfigFile;
	mxml_node_t *_NodeXml, *_NodeBouy;

	memset(_Buffer, 0, sizeof _Buffer);
	[[CCFileUtils fullPathFromRelativePath:@"file_config_library.xml"] getCString:_Buffer maxLength:sizeof _Buffer encoding:NSASCIIStringEncoding];
	_ConfigFile = fopen(_Buffer, "r");
	if (NULL != _ConfigFile)
	{
		_NodeXml = mxmlLoadFile(NULL, _ConfigFile, MXML_TEXT_CALLBACK);
		_NodeBouy = mxmlGetFirstChild(_NodeXml);
		for (; NULL != _NodeBouy; _NodeBouy = mxmlWalkNext(_NodeBouy, _NodeXml, MXML_NO_DESCEND))
		{
			/*main
			*/
			if (tmxmlIsElement(_NodeBouy, "library_main_ani_background"))
			{
				uiLoadAnimationObjectFromXML(_NodeBouy, &g_CfgLibraryMainAnimationBackground);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_main_image_box"))
			{
				uiLoadImageObjectFromXML(_NodeBouy, &g_CfgLibraryMainImageBox);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_main_item_experiment"))
			{
				uiLoadMenuItemImageObjectFromXML(_NodeBouy, &g_CfgLibraryMainItemExperiment);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_main_item_treasure"))
			{
				uiLoadMenuItemImageObjectFromXML(_NodeBouy, &g_CfgLibraryMainItemTreasure);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_main_item_credits"))
			{
				uiLoadMenuItemImageObjectFromXML(_NodeBouy, &g_CfgLibraryMainItemCredits);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_main_item_back"))
			{
				uiLoadMenuItemImageObjectFromXML(_NodeBouy, &g_CfgLibraryMainItemBack);
			}
			/*experiment
			*/
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_image_background"))
			{
				uiLoadImageObjectFromXML(_NodeBouy, &g_CfgLibraryExperimentImageBackgournd);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_image_container_rune"))
			{
				uiLoadImageObjectFromXML(_NodeBouy, &g_CfgLibraryExperimentImageContainerRune);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_image_container_heart"))
			{
				uiLoadImageObjectFromXML(_NodeBouy, &g_CfgLibraryExperimentImageContainerHeart);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_item_shake"))
			{
				uiLoadMenuItemImageObjectFromXML(_NodeBouy, &g_CfgLibraryExperimentItemShake);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_image_box_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryExperimentImageBoxPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_image_box_base_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryExperimentImageBoxBasePosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_experiment_image_box_size"))
			{
				uiLoadSizeFromXML(_NodeBouy, &g_CfgLibraryExperimentImageBoxSize);
			}
			/*treasure
			*/
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_label_weapon_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageLabelWeaopnPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_label_item_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageLabelItemPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_label_exhibition_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageLabelExhibitionPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_table_select_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageTableSelectPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_table_unselect_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageTableUnselectPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_item_weapon_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureItemTableWeaponPosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_item_item_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureItemTableItemPosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_item_exhibition_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureItemTableExhibitionPosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_cover_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageCoverPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_holder_back_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageHolderPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_detail_back_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageDetailBackPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_selected_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageSelectedPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_image_description_back_path"))
			{
				tmxmlElementReadChildText(_NodeBouy, g_CfgLibraryTreasureImageDescirptionBackPath);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_cover_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureCoverPosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_holder_base_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureHolderBasePosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_detail_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureDetailPosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_description_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureDescriptionPosition);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_description_text_base_position"))
			{
				uiLoadPointFromXML(_NodeBouy, &g_CfgLibraryTreasureDescriptionTextBasePostion);
			}
			else if (tmxmlIsElement(_NodeBouy, "library_treasure_item_back"))
			{
				uiLoadMenuItemImageObjectFromXML(_NodeBouy, &g_CfgLibraryTreasureItemBack);
			}
		}

		mxmlDelete(_NodeXml);
		fclose(_ConfigFile);
	}
	else
	{
		exit(1);
	}
}